//
//  ImageView.m
//  Rectiffy
//
//  Created by Jesper on 2007-07-14.
//  Copyright 2007 waffle software. All rights reserved.
//

#import "ImageView.h"


@implementation ImageView

- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
    }
    return self;
}

- (void)awakeFromNib {
	long stripe = 10; long step = stripe*2;
	long xy = 0; long xymax = step * 4;
	long siz = xymax / 2.0;
	NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(siz, siz)];
	[image lockFocus];
	[[NSColor whiteColor] setFill];
	[[NSBezierPath bezierPathWithRect:NSMakeRect(0,0,siz,siz)] fill];
	[[[NSColor gridColor] colorWithAlphaComponent:0.25] setFill];
	NSBezierPath *bp = [NSBezierPath bezierPath];
	for (xy = 0; xy < xymax; xy += step) {
		[bp moveToPoint:NSMakePoint(0,xy)];
		[bp lineToPoint:NSMakePoint(xy, 0)];
		[bp lineToPoint:NSMakePoint(xy+stripe,0)];
		[bp lineToPoint:NSMakePoint(0,xy+stripe)];
		[bp closePath];
	}
	[bp fill];
	[image unlockFocus];
	pattern = [[NSColor colorWithPatternImage:image] retain];	
}

- (void)drawRect:(NSRect)rect {
    if (!NSEqualSizes(rect.size,[self visibleRect].size)) { [self setNeedsDisplay:YES]; [self displayIfNeeded]; return; }
	[pattern setFill];
	[[NSBezierPath bezierPathWithRect:[self bounds]] fill];
	
	NSImageInterpolation ii = [[NSGraphicsContext currentContext] imageInterpolation];
	[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];	
	[super drawRect:rect];
	[[NSGraphicsContext currentContext] setImageInterpolation:ii];
}

@end
